package org.gwt.pluginframework.common;

import java.io.Serializable;
import java.util.List;

/**
 * Plugin manifest store essential information about plug-in. 
 * 
 * Need for monitor and dependency check.
 * 
 * @author mszymanski
 */
public class PluginManifest implements Serializable {
	private static final long serialVersionUID = -8344975118938339672L;

	private String name;
	
	private String version;
	
	private String comment;
	
	protected PluginState state = PluginState.UNINITIALIZED;
	
	private List<PluginManifest> dependency;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public List<PluginManifest> getDependency() {
		return dependency;
	}

	public void setDependency(List<PluginManifest> dependency) {
		this.dependency = dependency;
	}

	public PluginState getState() {
		return state;
	}

	public void setState(PluginState state) {
		this.state = state;
	}
	
	private boolean empty(String txt) {
		return name == null || "".equals(txt);
	}
	
	void validate() {
		if(empty(name)) {
			throw new IllegalStateException("Plugin description is invalid! Name is empty!");
		}
		if(empty(version)) {
			throw new IllegalStateException("Plugin description is invalid! Version is empty!");
		}
	}
}
